﻿component 
{
    this.ApplicationTimeout = CreateTimeSpan( 0, 0, 90, 0 );
    this.SessionManagement = true;
    this.SessionTimeout = CreateTimeSpan(0,0,20,0);    
    this.SetClientCookies = true;    
    /*  CF9 ORM settings */ 
    this.Datasource = "DynamicGroupManagement";
    this.ormenabled = true;
    this.ormsettings = {
        logsql = true,
        dbcreate = "none",
        cfclocation = "models"
    };
    
    public boolean function onApplicationStart(){
        APPLICATION.version = "1.0";
        APPLICATION.Name = "Dynamic Group Management";
        APPLICATION.HeaderName = "Dynamic Group Management";
        //*** OPTIONAL - If you use Encrypt(), Decrypt(), it makes sense to specify your encryption string here.
        APPLICATION.ENCRYPTION_ALGORITHM = "RC4";
        APPLICATION.ENCRYPTION_ENCODING = "hex";
        APPLICATION.ENCRYPTION_KEY = "VEDKEY";        
        return true;
    }


    public void function onApplicationEnd(ApplicationScope){

    }


    public void function onRequest(String targetPage){
        include arguments.targetPage;
    }


    public boolean function onRequestStart(String targetPage){
        ORMReload(); /* CF9 ORM setting  */    
        return true;
    }


    public void function onRequestEnd(String targetPage){

    }


    public void function onSessionStart(){
        Var FUNC = StructNew();
        session.rootDir = ListGetAt(CGI.PATH_INFO,1,"/");
        session.Authenticated = false;
        SESSION.IsPasswordGood = 0;
        if( !IsDefined("SCF_Employee_GetEmpInfo_FromLogin") ){
            include "/code_lib/SCF_Employee.cfm";        
        }
        SESSION.myUserInfo = SCF_Employee_GetEmpInfo_FromLogin(ListGetAt(CGI.AUTH_USER, 2, '\'),ListGetAt(CGI.AUTH_USER, 1, '\'));
        session.authuser = ListGetAt(CGI.Auth_User, 2, '\');
        SESSION.IsPasswordGood = 0;
        
        UserQuery = new query();
        UserQuery.setAttributes(GetAllUsers = CreateObject("component", "code_lib.SCF_ActiveDirectory").getAllUsers() );
        UserQuery.setcachedwithin(CreateTimeSpan(0, 0, 20, 0));
        UserQuery = UserQuery.execute(sql="SELECT * FROM GetAllUsers", dbtype="query");
        
        GroupQuery = new query();
        GroupQuery.setAttributes(GetAllGroups = CreateObject("component", "code_lib.SCF_ActiveDirectory").getAllGroups() );
        GroupQuery.setcachedwithin(CreateTimeSpan(0, 0, 20, 0));
        GroupQuery = GroupQuery.execute(sql="SELECT * FROM GetAllGroups", dbtype="query");
        
        session.AllADUsers = UserQuery.getResult();
        session.AllADGroups = GroupQuery.getResult();
    }


    public void function onSessionEnd(SessionScope,ApplicationScope){

    }


    public boolean function onMissingTemplate(String targetPage) {

        return true;
    }

    /*public function onError(required any Exception, required string EventName)
    {
          developerEMail = "bfrick@scf.cc";  // Your e-mail here, or SCFAppNotifyAdmin@scf.cc
    
          WriteLog(type="Error", text="#UCase(Exception.Type)# ERROR:  #Exception.Message#    LOCATION: #CGI.SERVER_NAME##CGI.SCRIPT_NAME#, Line #Exception.TagContext[1].Line#.");
                
          // E-Mail the Error
          mail=new mail();
          mail.setType("html");
          mail.setFrom("Your Friendly ColdFusion Server <noreply@scf.cc>");
          mail.setTo(developerEMail);         
          mail.setSubject("Doh! Error in #APPLICATION.ApplicationName#");
          savecontent variable="eMailBody" {
            include "/code_lib/SCF_Standard_Error_EMail.cfm";
          }
          mail.addPart(type="html", charset="utf-8", body="#eMailBody#");
          mail.send();
                
          // Display the Error
          include "/code_lib/SCF_Standard_Error_Display.cfm";
                
          // Throw the Error (for Dev Only)
          throw(ARGUMENTS.Exception);
                
    }*/


    //Uncomment below to handle this type of exception
    /*public void function onMissingMethod(String method,Struct args) {

    }*/


    public void function onCFCRequest(String cfcname,String method,Struct args){

    }

}